package com.self.task;

import com.alibaba.fastjson.JSONObject;

import java.util.List;
import java.util.Map;

public class LogStackUtil {

    public static void logStack() {

        List<ThreadInfo> threads = ThreadInfo.getAllThreadInfos();
        StringBuilder sb = new StringBuilder();
        for(ThreadInfo thread : threads) {
            sb.append('\n');
            sb.append(thread.toString());
        }

        JSONObject json = new JSONObject(true);
        setKVToMap(json, "stacks", sb.toString());

//        System.out.println(json);
    }

    private static void setKVToMap(Map<String, Object> json, String key, Object value) {
        if(value == null) {
            return;
        }

        json.put(key, value);
    }

}
